
package udes.ds.agent;

import javax.naming.directory.InvalidAttributesException;
import udes.ds.agent.AbstractEquation;

public class ExponentialEquation extends AbstractEquation {
	private static final long	 serialVersionUID	= 1L;
	private double _coefficient;
	private AbstractEquation _exponent;
	
	public ExponentialEquation(double coefficient, AbstractEquation exponent) {
		super();
		_coefficient = coefficient;
		_exponent = exponent;
	}

	/**  
	 * @see udes.ds.rmi.hw.Equation#getFunctionValue(double)      
	 */
	public double getFunctionValue(double x) {
		return _coefficient * (Math.pow(Math.E,_exponent.getFunctionValue(x)));
	}

	/**   
	 * @see udes.ds.rmi.hw.Equation#printUserReadable()      
	 */
	public void printUserReadable() {
		System.out.println("y = " + this.getUserReadableString());
	}

	/**  
	 * @see udes.ds.rmi.hw.Equation#getUserReadableString()      
	 */
	public String getUserReadableString() {
		return new String(Double.toString(_coefficient)) + "e^(" + _exponent.getUserReadableString() + ")";
	}
	
	@Override
	public Object[] getValues() {
		return new Object[] {_coefficient, _exponent};
	}

	@Override
	public void setValues(Object[] aObjects) throws InvalidAttributesException 
	{
		int i = 0;
		if (aObjects.length == 2)
		{
			if(aObjects[0] instanceof Double)	
			{
				_coefficient = (Double)aObjects[0];
				++i;
			}
			if(aObjects[1] instanceof AbstractEquation)
			{
				_exponent = (AbstractEquation)aObjects[1];
				++i;
			}
		}
		
		if(i != 2)
		{
			throw new InvalidAttributesException();
		}
	}
}